/////////////////////////////////////////////////////////////////////////////
// Copyright(c) 2012-2015 purang All Rights Reserved
// Name:        network_base.h
// Purpose:     
// Author:      syy
// Modified by: 
// Created:     2014/5/11 15:42
// RCS-ID:      
// Licence:     
/////////////////////////////////////////////////////////////////////////////
#ifndef _NetworkService_SOCKETBASE_H_
#define _NetworkService_SOCKETBASE_H_

#include <vector>
#include "../sock/socket_impl.h"
#include "../include/network_service.h"
#include <core/common_types.h>
#include <core/system/critical_section_wrapper.h>
#include <core/system/event_wrapper.h>
#include <core/system/atomic32.h>
#include <core/observer/message_observer.h>

namespace qb
{
	class CSocketBase
		: public CSocketImpl
		, public ISocketObserver
	{
	public:
		CSocketBase(SocketType sock_type);
		virtual ~CSocketBase(void);

		virtual int32_t InitlizeSocket(int32_t socket_id);
		virtual int32_t RegisterSocketObserver(INetworkServiceObserver* observer);
		virtual int32_t DeRegisterSocketObserver(INetworkServiceObserver* observer);
		virtual int32_t Connect(const char* ipAddressUTF8,uint16_t port);
		
	protected:
		// ISocketObserver
		virtual void OnConnected();
		virtual void OnSendFailed();
		virtual void OnRecvFailed();
        virtual void OnRecvMessage(MESSAGE_SHARED_PTR msp);
        virtual void OnRecvMessage2(const char* buf,uint32_t buf_size);

	protected:
		SocketType								m_sock_type;
		CriticalSectionWrapper&					m_callbackCritSect;
		BList<INetworkServiceObserver*>			m_observers;
		int32_t									m_socket_id;
	};
}

#endif // _NetworkService_SOCKETBASE_H_
